home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / www / HTTX.lha / AWeb / HTTXPlugin.awebrx < prev    next >
Text File  |  1997-07-16  |  6KB  |  290 lines

  1. /*
  2.     Convert current document to TEXT using HTTX
  3.     $VER: HTTXPlugin 2.0 (1.5.97) by Gabriele Favrin (favrin@tin.it)
  4. */
  5.  
  6. Options Results
  7. Options failat 999
  8.  
  9. Parse ARG mode mode_data .
  10.  
  11. 'GetCFG TEMPPATH VAR' prefs_temppath
  12.  
  13. req_title = '"Save as text"'
  14. temp_out     = prefs_temppath"temp_HTTXP_Output.txt"
  15. temp_name = prefs_temppath"temp_HTTXP_file"
  16. eol         = '0A'x
  17. trg         = ""
  18. del_list     = prefs_temppath"temp_HTTXP_#?"
  19. force         = ""
  20. writeflag = "W"
  21. string     = "HTTXPlugin V2.0"||eol||eol
  22. option     = ""
  23.  
  24. prefs_info     = 0
  25. prefs_preview= 0
  26. prefs_report = 1
  27. prefs_savedir= "ram:"
  28.  
  29. Call readcfg()
  30.  
  31. If (mode == "TARGET") then
  32.     trg="TARGET" mode_data
  33.  
  34. 'Get URL VAR' doc_url trg
  35. org_url=doc_url
  36.  
  37. 'GetCFG HTMLMODE'
  38. If result == 0 then
  39.     frms.0=0
  40. else
  41.     'Get FRAMES ALL' trg 'STEM' frms
  42.  
  43. If (frms.0 = 0) then do
  44.     If getName() == 1 then do
  45.         Call SaveHTML()
  46.         Call Convert()
  47.         Call CleanUp()
  48.     End
  49. End
  50. else do
  51.     prefs_report=0
  52.  
  53.     'Request' req_title '"Selected document contains frames." "Convert _All|_Select frame(s)|_Cancel"'
  54.     If rc == 5 then exit()
  55.     option=result
  56.  
  57.     If option == 1 then do
  58.         If getName() == 0 then do
  59.             exit 0
  60.         End
  61.     End
  62.  
  63.     do ct=1 for frms.0
  64.         doc_url=frms.ct.url
  65.         trg="TARGET="frms.ct.id
  66.  
  67.         If option == 1 then do
  68.             If ct > 1 then do
  69.                 writeflag="A"
  70.                 string=eol||eol||"----"||eol||eol
  71.             End
  72.  
  73.             Call SaveHTML()
  74.             Call Convert()
  75.             Call CleanUp()
  76.         End
  77.         else do
  78.             'Open "'frms.ct.url'"'
  79.             'Wait "'frms.ct.url'"'
  80.  
  81.             'Request' req_title '"Convert this frame?" _Yes|_No|_Cancel'
  82.             If rc == 5 then do
  83.                 Call CleanUp()
  84.                 'Open "'org_url'"'
  85.                 exit()
  86.             End
  87.  
  88.             If result == 1 then do
  89.                 trg=""
  90.                 string = "HTTXPlugin V2.0"||eol||eol
  91.  
  92.                 If getName() == 1 then do
  93.                     Call SaveHTML()
  94.                     Call Convert()
  95.                     Call CleanUp()
  96.                 End
  97.             End
  98.         End
  99.     End
  100.  
  101.     If option == 1 then do
  102.         If prefs_preview == 1 then do
  103.             If preview() == 1 then do
  104.                 Call displayOutput()
  105.             End
  106.         End
  107.         else do
  108.             Call displayOutput()
  109.         End
  110.         Call CleanUp()
  111.     End
  112.     else do
  113.         if option == 2 then do
  114.             'Open "'org_url'"'
  115.         end
  116.     end
  117. End
  118.  
  119. exit 0
  120.  
  121.  
  122. CleanUp:
  123.     address command 'C:Delete >NIL: QUIET' del_list
  124.  
  125.     last_slash_pos=LastPos('/', save_file)
  126.     if last_slash_pos == 0 then do
  127.         pos_colon=Pos(':', save_file)
  128.         if prefs_savedir ~= left(save_file, pos_colon) then do
  129.             prefs_savedir=left(save_file, pos_colon)
  130.  
  131.             address command 'SetEnv HTTXPlugin.savedir "'prefs_savedir'"'
  132.         end
  133.     end
  134.     else do
  135.         if prefs_savedir ~= left(save_file, last_slash_pos) then do
  136.             prefs_savedir=left(save_file, last_slash_pos)
  137.             address command 'SetEnv HTTXPlugin.savedir "'prefs_savedir'"'
  138.         end
  139.     end
  140.     return
  141.  
  142.  
  143. SaveHTML:
  144.     'SaveAs "'temp_name'" NOICON' trg
  145.     If rc ~= 0 then do
  146.         'Request req_title "Error while saving HTML on temporary path*N *N'prefs_temppath'" _Ops'
  147.         exit 0
  148.     End
  149.     return
  150.  
  151.  
  152. GetName:
  153.     html_name=Translate(doc_url,,'`"=#?/:;\*%')
  154.     html_name=Translate(html_name,,"'")
  155.     html_name=Word(html_name, Words(html_name))
  156.  
  157.     'RequestFile 'req_title' FILE="'prefs_savedir||html_name'.txt" SAVEMODE'
  158.     If (rc == 5) then return 0
  159.     save_file=result
  160.  
  161.     If (Right(save_file, 1) == ":") | (Right(save_file, 1) == "/") then
  162.         save_file=save_file||html_name'.txt'
  163.  
  164.     html_name=prefs_temppath||html_name
  165.     return 1
  166.  
  167.  
  168. convert:
  169.     'Get MIME VAR' mtype trg
  170.     If (Upper(mtype) == "TEXT/HTML") then
  171.         drop force
  172.     else
  173.         force=""
  174.  
  175.     Call PrepareFile()
  176.  
  177.     res=httx()
  178.     If (res == 212) then do
  179.         'Request 'req_title' "File is not html! Save anyway?" "_Save|_Cancel"'
  180.  
  181.         If (rc ~= 5) then do
  182.             address command 'C:Copy "'temp_name'" "'save_file'"'
  183.             prefs_report=0
  184.             res=0
  185.             Call displayOutput()
  186.         End
  187.     End
  188.     else do
  189.         If option ~= 1 then do
  190.             If (res ~= 0) then do
  191.                 del_list=del_list '"'save_file'"'
  192.                 If option ~= 2 then do
  193.                     Call displayOutput()
  194.                 End
  195.             End
  196.             else do
  197.                 If prefs_preview == 1 then do
  198.                     If preview() == 1 then do
  199.                         If option ~= 2 then do
  200.                             Call displayOutput()
  201.                         End
  202.                     End
  203.                 End
  204.                 else do
  205.                     If option ~= 2 then do
  206.                         Call displayOutput()
  207.                     End
  208.                 End
  209.             End
  210.         End
  211.     End
  212.     return
  213.  
  214.  
  215. httx:
  216.     address command 'plugins/httx/HTTX >'temp_out' "'temp_name'" "'save_file'" APPEND' force
  217.     return rc
  218.  
  219.  
  220. displayOutput:
  221.     If (prefs_report == 1) then do
  222.         'Open "file://localhost/'temp_out'" RELOAD'
  223.         'Wait "file://localhost/'temp_out'"'
  224.     End
  225.     else do
  226.         If (res == 0) then do
  227.             'Request 'req_title' "File saved as*N'save_file'" _Ok! NOWAIT'
  228.         End
  229.         else do
  230.             'Request 'req_title' "Error 'rc'" _Ok! NOWAIT'
  231.         End
  232.     End
  233.     return
  234.  
  235.  
  236. preview:
  237.     'Get SCREEN VAR' prefs_screen
  238.     address command 'SYS:Utilities/Multiview 'save_file' pubscreen='prefs_screen
  239.     drop result
  240.  
  241.     'Request 'req_title' "File converted." "_Ok|_Delete"'
  242.  
  243.     If (result ~= 1) then do
  244.         del_list=del_list '"'save_file'"'
  245.     End
  246.     return result
  247.  
  248.  
  249. PrepareFile:
  250.     If Open(fp, save_file, writeflag) then do
  251.         If (prefs_info == 1) then do
  252.             'Get INFO STEM' infos trg
  253.             If (infos.0 > 0) then do
  254.                 string=string||eol||"Header:"||eol
  255.  
  256.                 do ctx=1 for infos.0
  257.                     If (infos.ctx.type ~= "CACHE") then do
  258.                         string=string||infos.ctx.value||eol
  259.                         If infos.ctx.type == "LINK" then string=string||eol||infos.ctx.url
  260.                     End
  261.                 End
  262.             End
  263.         End
  264.  
  265.         WriteCH(fp, string)
  266.         Call Close(fp)
  267.     End
  268.     return
  269.  
  270.  
  271. readcfg:
  272.     If Open(rcfg_fp, 'ENV:HTTXPlugin.config', 'R') then do
  273.         cfg=ReadLN(rcfg_fp)
  274.  
  275.         If Left(cfg, 6) == "prefs_" then do
  276.             interpret translate(strip(cfg), ';',' ')
  277.             prefs_savedir=Translate(prefs_savedir, ' ', ';')
  278.         End
  279.  
  280.         Call Close(rcfg_fp)
  281.     End
  282.  
  283.     If Open(rcfg_fp, 'ENV:HTTXPlugin.savedir', 'R') then do
  284.         prefs_savedir2=ReadLN(rcfg_fp)
  285.         If prefs_savedir2 ~= "" then prefs_savedir=prefs_savedir2
  286.         Call Close(rcfg_fp)
  287.     End
  288.     return
  289.  
  290.